package coasttocoast.client.controllers;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 * Central controller for events and actions in the game.
 *
 * @author gsh
 */
public final class GameController {
  private static Logger logger = Logger.getLogger(GameController.class.getName());
  private static GameController controller = new GameController();

  private List<GameListener> gameListeners = new ArrayList<GameListener>();

  private GameController() {
    // Prevent construction by other classes.  
  }

  /**
   * Returns singleton instance of the GameController
   * @return
   */
  public static GameController get() {
    return controller;
  }

  public boolean canExit() {
    return true;  
  }

  public void saveGame() {
    logger.info("saveGame request");
  }

  public void addGameListener(GameListener listener) {
    gameListeners.add(listener);
  }

  public void removeGameListener(GameListener listener) {
    gameListeners.remove(listener);
  }

  public void fireStart() {
    logger.info("Starting game");
    for (GameListener listener : gameListeners) {
      listener.start();
    }
  }

  public void fireEnd() {
    logger.info("Ending game");
    for (GameListener listener : gameListeners) {
      listener.end();
    }
  }
}
